﻿#pragma once

#include "MirControl.h"
#include <string>
#include "../../tangible_event.h"

using namespace Client::MirGraphics;
using namespace SlimDX;
using namespace SlimDX::Direct3D9;
//C# TO C++ CONVERTER TODO TASK: C# to C++ Converter could not confirm whether this is a namespace alias or a type alias:
//using Font = System::Drawing::Font;

namespace Client::MirControls
{
    class MirLabel : public MirControl
    {
        #pragma region Auto Size
    private:
        bool _autoSize = false;
    public:
        virtual ~MirLabel()
        {
            delete _drawFormat;
            delete _font;
            delete _outLineColour;
        }

        bool getAutoSize() const;
        void setAutoSize(bool value);
        TangibleEvent<EventHandler> *AutoSizeChanged = new TangibleEvent<EventHandler>();
    private:
        void OnAutoSizeChanged(EventArgs *e);
        #pragma endregion

        #pragma region DrawFormat
        TextFormatFlags *_drawFormat;
    public:
        TextFormatFlags *getDrawFormat() const;
        void setDrawFormat(TextFormatFlags *value);
        TangibleEvent<EventHandler> *DrawFormatChanged = new TangibleEvent<EventHandler>();
    private:
        void OnDrawFormatChanged(EventArgs *e);
        #pragma endregion

        #pragma region Font
        System::Drawing::Font *_font;
    public:
        System::Drawing::Font *getFont() const;
        void setFont(System::Drawing::Font *value);
        TangibleEvent<EventHandler> *FontChanged = new TangibleEvent<EventHandler>();
    private:
        void OnFontChanged(EventArgs *e);
        #pragma endregion

        #pragma region Out Line
        bool _outLine = false;
    public:
        bool getOutLine() const;
        void setOutLine(bool value);
        TangibleEvent<EventHandler> *OutLineChanged = new TangibleEvent<EventHandler>();
    private:
        void OnOutLineChanged(EventArgs *e);
        #pragma endregion

        #pragma region Out Line Colour
        Color *_outLineColour;
    public:
        Color *getOutLineColour() const;
        void setOutLineColour(Color *value);
        TangibleEvent<EventHandler> *OutLineColourChanged = new TangibleEvent<EventHandler>();
    private:
        void OnOutLineColourChanged();
        #pragma endregion

        #pragma region Size

        void GetSize();
        #pragma endregion

        #pragma region Label
        std::string _text;
    public:
        std::string getText() const;
        void setText(const std::string &value);
        TangibleEvent<EventHandler> *TextChanged = new TangibleEvent<EventHandler>();
    private:
        void OnTextChanged(EventArgs *e);
        #pragma endregion

    public:
        MirLabel();

//C# TO C++ CONVERTER TODO TASK: C# 'unsafe' code is not converted by C# to C++ Converter:
//        protected override unsafe void CreateTexture()
//        {
//            if (string.IsNullOrEmpty(Text))
//                return;
//
//            if (Size.Width == 0 || Size.Height == 0)
//                return;
//
//            if (ControlTexture != nullptr && !ControlTexture.Disposed && TextureSize != Size)
//                ControlTexture.Dispose();
//
//            if (ControlTexture == nullptr || ControlTexture.Disposed)
//            {
//                DXManager.ControlList.Add(this);
//
//                ControlTexture = new Texture(DXManager.Device, Size.Width, Size.Height, 1, Usage.None, Format.A8R8G8B8, Pool.Managed);
//                TextureSize = Size;
//            }
//
//            DataRectangle stream = ControlTexture.LockRectangle(0, LockFlags.Discard);
//            using (Bitmap image = new Bitmap(Size.Width, Size.Height, Size.Width * 4, PixelFormat.Format32bppArgb, stream.Data.DataPointer))
//            {
//                using (Graphics graphics = Graphics.FromImage(image))
//                {
//                    graphics.SmoothingMode = SmoothingMode.AntiAlias;
//                    graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
//                    graphics.CompositingQuality = CompositingQuality.HighQuality;
//                    graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
//                    graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
//                    graphics.TextContrast = 0;
//                    graphics.Clear(BackColour);
//
//
//                    if (OutLine)
//                    {
//                        TextRenderer.DrawText(graphics, Text, Font, new Rectangle(1, 0, Size.Width, Size.Height), OutLineColour, DrawFormat);
//                        TextRenderer.DrawText(graphics, Text, Font, new Rectangle(0, 1, Size.Width, Size.Height), OutLineColour, DrawFormat);
//                        TextRenderer.DrawText(graphics, Text, Font, new Rectangle(2, 1, Size.Width, Size.Height), OutLineColour, DrawFormat);
//                        TextRenderer.DrawText(graphics, Text, Font, new Rectangle(1, 2, Size.Width, Size.Height), OutLineColour, DrawFormat);
//                        TextRenderer.DrawText(graphics, Text, Font, new Rectangle(1, 1, Size.Width, Size.Height), ForeColour, DrawFormat);
//
//                        //LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, this.Size.Width, this.Size.Height), Color.FromArgb(239, 243, 239), Color.White, LinearGradientMode.Vertical);
//                        ////graphics.DrawString(Text, Font, brush, 37, 9);
//                        ////graphics.DrawString(this.Text, this.Font, new SolidBrush(Color.Black), 39, 9, StringFormat.GenericDefault);
//                    }
//                    else
//                        TextRenderer.DrawText(graphics, Text, Font, new Rectangle(1, 0, Size.Width, Size.Height), ForeColour, DrawFormat);
//                }
//            }
//
//            ControlTexture.UnlockRectangle(0);
//            DXManager.Sprite.Flush();
//            TextureValid = true;
//        }

        #pragma region Disposable
    protected:
        void Dispose(bool disposing) override;
        #pragma endregion

    };
}
